package org.cheniy.domain.strategy.model.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.cheniy.types.common.Constants;

/**
 * @author cheniy
 * @description Strategy需要的StrategyAward对象
 * @create 2025/3/1 23:37
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {

    /** 抽奖策略ID */
    private Long strategyId;
    /** 抽奖策略描述 */
    private String strategyDesc;
    /** 抽奖规则模型 rule_weight,rule_blacklist */
    private String ruleModels;

    // 充血方法

    /**
     * 查询策略中的规则模型
     * @return
     */
    public String[] ruleModels(){
        if (StringUtils.isBlank(ruleModels)) return null;
        return ruleModels.split(Constants.SPLIT);
    }

    /**
     * 获取ruleModels中的RuleWeight的值
     * @return
     */
    public String getRuleWeight(){
        String[] ruleModels =this.ruleModels();
        if (ruleModels==null) return null;
        for (String ruleModel:ruleModels){
            if ("rule_weight".equals(ruleModel)) return ruleModel;
        }
        return null;
    }

}
